package com.lenovo.agricultureServer.http.action;

import org.json.JSONException;
import org.json.JSONObject;

import com.lenovo.agricultureServer.Serial.SerialportService;
import com.lenovo.agricultureServer.bean.Sensor;

public class GetSensorAction extends BaseAction 
{
	public static final String TAG = "getSensor";
	
	@Override
	protected String jasonPorcess(String param) 
	{
		JSONObject jsonResponse = new JSONObject();
		try 
		{
			jsonResponse.put("pm2.5", SerialportService.getSensorValueByName(Sensor.PM25_SENSOR));
			jsonResponse.put("co2", SerialportService.getSensorValueByName(Sensor.CO2_SENSOR));
			
			jsonResponse.put("airTemperature", SerialportService.getSensorValueByName(Sensor.AIR_TMPER_SENSOR));
			jsonResponse.put("airHumidity", SerialportService.getSensorValueByName(Sensor.AIR_HUMID_SENSOR));
			jsonResponse.put("soilTemperature", SerialportService.getSensorValueByName(Sensor.SOIL_TMPER_SENSOR));
			jsonResponse.put("soilHumidity", SerialportService.getSensorValueByName(Sensor.SOIL_HUMID_SENSOR));
			jsonResponse.put("light", SerialportService.getSensorValueByName(Sensor.LIGHT_SENSOR));
			
			jsonResponse.put("result", "ok");
			return jsonResponse.toString();
		} 
		catch (JSONException e) 
		{
			e.printStackTrace();
		}
		catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	protected String soapPorcess(String param) {
		//TODO
		return "";
	}

}
